home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / self / contrib.lha / contrib / 491 / aa / eventHandler.self < prev    next >
Encoding:
Text File  |  1993-07-22  |  8.1 KB  |  288 lines

  1. " objects to hold various state dependant event handling.
  2. *
  3. * eventHandler.self,v 1.3 1993/07/22 00:15:16 richards Exp
  4. *
  5. * eventHandler.self,v
  6. # Revision 1.3  1993/07/22  00:15:16  richards
  7. # Moved back to having event handlers per operation.
  8. # eventHandler/buttons now support substitution.
  9. # poly.self has primitive substitution handler, except that it has
  10. # no concept of context.
  11. #
  12. # Revision 1.2  1993/07/18  20:22:29  richards
  13. # Added substitution of polynomials (not quite working properly yet).
  14. # Some tests for this added to test4.
  15. # Buttons work, selections work, and eventHandling is coming along.
  16. #
  17. # Revision 1.1  1993/07/14  21:42:08  richards
  18. # Moved event handling out of the equationView and into a seperate set of object.
  19. # Equation selecting works!
  20. #
  21. *
  22. *
  23. **************************
  24. *****     STATE       ****
  25. **************************
  26. "
  27.  
  28. " :=(ADDSLOTS)=: "
  29. aa _AddSlotsIfAbsent: (| editor = () |).
  30.  
  31. aa editor _AddSlotsIfAbsent: (|
  32.     ^ prototypes* = ().
  33.     ^ oddballs*   = ().
  34.     ^ traits      = ().
  35.     ^ mixins      = ().
  36. |)
  37.  
  38. " :=(TRAITS DEFINITIONS)=:aa editor"
  39. aa editor traits _AddSlotsIfAbsent: (|
  40.     genericEventHandler            = ().
  41.     selectionEventHandler        = ().
  42.     areaSelectionHandler        = ().
  43.     substitutionSelectionEventHandler    = ().
  44.     substituteeSelectionEventHandler    = ().
  45. |)
  46.  
  47. aa editor prototypes _AddSlotsIfAbsent: (|
  48.     genericEventHandler            = ().
  49.     selectionEventHandler        = ().
  50.     areaSelectionHandler        = ().
  51.     substitutionSelectionEventHandler    = ().
  52.     substituteeSelectionEventHandler    = ().
  53. |)
  54.  
  55. aa editor traits genericEventHandler _Define: (|
  56.     _ parent*                 = traits clonable.
  57.     ^ copy = ( clone ).
  58.     ^ copyForView: vue = ( |c|
  59.     c: copy.
  60.     c vue: vue.
  61.     c
  62.     ).
  63.  
  64.     ^ selectUp: pt    = (42).
  65.     ^ selectDown: pt  = (42).
  66.     ^ copyUp: pt      = (42).
  67.     ^ copyDown: pt    = (42).
  68.     ^ menuUp: pt      = (42).
  69.     ^ menuDown: pt    = (42).
  70.     ^ motion: pt      = (42).
  71.     ^ enter: pt          = (
  72.     vue topView caption: instructionText
  73.     ).
  74.     
  75.     ^ isSelectionHandler     = (false).
  76.     ^ isAreaSelectionHandler = (false).
  77.     ^ isSubstitutionHandler  = (false).
  78.  
  79.     instructionText = ( 'Handler: ', handlerName ).
  80.     handlerName = ('generic').
  81.  
  82.     printString = ( '<eventHandler>' , handlerName).
  83.  
  84.     resetHandler = (
  85.     vue topView handlerForNextWindow: aa editor selectionEventHandler.
  86.     vue viewHandler isSelectionHandler ifFalse: [
  87.         vue viewHandler: aa editor selectionEventHandler copyForView: vue.
  88.     ].
  89.     ).
  90. |)
  91.  
  92. aa editor prototypes genericEventHandler _Define: (|
  93.     ^ parent*                 = aa editor traits genericEventHandler.
  94.     vue.
  95. |)
  96.  
  97. aa editor traits selectionEventHandler _Define: (|
  98.     ^ parent*                 = aa editor traits genericEventHandler.
  99.     ^ copy = (|c|
  100.     c: resend.copy.
  101.     c
  102.     ).
  103.  
  104.     instructionText = ( 'Left: selects/expands Middle: picks Right: cancel' ).
  105.     handlerName = ('selection').
  106.  
  107.     ^ selectDown: pt = (
  108.     'equationBBox: ' print.
  109.     vue equationBBox printLine.
  110.     'pt: ' print.
  111.     pt printLine.
  112.     (vue equationBBox includes: pt) ifTrue: [
  113.         vue subViewDo: [| :aSv. |
  114.         aSv unHighlight
  115.         ].
  116.         vue subViewDo: [| :aSv. |
  117.         aSv selectDown: pt WithSelection: equationSelection
  118.         ].
  119.     ] False: [
  120.         equationSelection becomeUnselected.
  121.     ].
  122.     vue redraw.
  123.     ).
  124.  
  125.     ^ selectUp: pt = (
  126.     equationSelection isValidSelection ifTrue: [
  127.         'Selected: ' print.
  128.         equationSelection selectedPolynum printLine.
  129.     ]
  130.     ).
  131.     ^ isSelectionHandler = (true).
  132.  
  133.     setupNextEventHandler = (
  134.     'default setupNextEventHandler' printLine.
  135.     resetHandler.
  136.     ).
  137.  
  138.     cancelEventHandler = (
  139.     equationSelection becomeUnselected.
  140.     resetHandler.
  141.     ).
  142.  
  143.     copyUp: pt = (
  144.     setupNextEventHandler.
  145.     ).
  146.  
  147.     " Cancel "
  148.     menuUp: pt = (
  149.     cancelEventHandler.
  150.     ).
  151.  
  152. |)
  153.  
  154. aa editor prototypes selectionEventHandler _Define: aa editor genericEventHandler
  155. aa editor prototypes selectionEventHandler _AddSlots: (|
  156.     ^ parent*           = aa editor traits selectionEventHandler.
  157.     ^ equationSelection      <- aa editor unselectedPortion copy.
  158. |)
  159.  
  160. aa editor traits areaSelectionHandler _Define: (|
  161.     ^ parent*                 = aa editor traits genericEventHandler.
  162.     ^ copy = (|c|
  163.     c: resend.copy
  164.     c
  165.     ).
  166.  
  167.     instructionText = (
  168.     areaSelect isNil ifTrue: ['Left: first point  Middle: nothing   Right: cancel']
  169.           False: ['Left: second point  Middle: second point   Right: cancel']
  170.     ).
  171.  
  172.     ^ selectUp: pt = (
  173.      areaSelect isNil ifTrue: [
  174.         areaSelect: pt#pt.
  175.         vue eventMaskAdd: (xlib events pointerMotionMask || xlib events buttonMotionMask). " XXX - don't assume that it is button 2! "
  176.         vue drawXorRectangle: areaSelect.
  177.         vue topView caption: instructionText
  178.     ] False: [ copyUp: pt ].
  179.     ).
  180.  
  181.     ^ menuUp: pt = (
  182.     areaSelect: nil.
  183.     vue eventMaskRemove: (xlib events pointerMotionMask || xlib events buttonMotionMask || xlib events button2MotionMask). " XXX -- see above "
  184.     vue topView caption: instructionText.
  185.     ).
  186.  
  187.     ^ motionNotify: event = (
  188.     vue drawXorRectangle: areaSelect. "Undraw rubber band"
  189.     areaSelect: (areaSelect origin)#(event x@event y).
  190.     vue drawXorRectangle: areaSelect.
  191.     ).
  192.  
  193.     ^ copyUp: pt = (
  194.     vue eventMaskRemove: (xlib events pointerMotionMask || xlib events buttonMotionMask || xlib events button2MotionMask). " XXX -- see above "
  195.     vue drawXorRectangle: areaSelect.
  196.     areaSelect: (areaSelect origin)#pt.
  197.     equationSelection becomeUnselected.
  198.     vue subViewDo: [| :aSv |
  199.         (aSv area intersects: areaSelect) ifTrue: [
  200.         aSv highlight.
  201.         ].
  202.     ].
  203.     " now find a common ancestor! "
  204.     " then redraw "
  205.     vue redraw.
  206.     ).
  207.  
  208.     ^ isAreaSelectionHandler = (true).
  209. |)
  210.  
  211.  
  212. aa editor prototypes areaSelectionHandler _Define: aa editor genericEventHandler.
  213. aa editor prototypes areaSelectionHandler _AddSlots: (|
  214.     ^ parent*           = aa editor traits areaSelectionHandler.
  215.     ^ equationSelection      <- aa editor unselectedPortion copy.
  216.     areaSelect.
  217. |)
  218.  
  219. " This event handler is a specialization of the selection handler. "
  220. " After the selection is ratified, the selection is unselected, recorded "
  221. " and then that window, and the one entered get a new selection handler  "
  222.  
  223. aa editor traits substitutionSelectionEventHandler _Define: (|
  224.     _ parent*                 = aa editor traits selectionEventHandler.
  225.  
  226.     ^ copy = (| c. |
  227.     c: resend.copy.
  228.     c
  229.     ).
  230.  
  231.     instructionText = ( 'Left: selects/expands Middle: picks Right: cancel' ).
  232.     handlerName = ('substitutionSelection').
  233.     isSubstitutionHandler = (true).
  234.  
  235.     copyUp: pt = (| nh. |
  236.     equationSelection isValidSelection ifTrue: [
  237.         nh: aa editor substituteeSelectionEventHandler copy.
  238.         nh substitutor: equationSelection selectedPolynum.
  239.         vue topView handlerForNextWindow: nh.
  240.         vue viewHandler: nh.
  241.         equationSelection becomeUnselected.
  242.     ] False: [
  243.         vue topView userError: 'You must select something before picking it.'
  244.     ].
  245.     ).
  246.  
  247. |)
  248.  
  249. aa editor prototypes substitutionSelectionEventHandler _Define: aa editor selectionEventHandler.
  250. aa editor prototypes substitutionSelectionEventHandler _AddSlots: (|
  251.     _ parent*                 = aa editor traits substitutionSelectionEventHandler.
  252. |)
  253.  
  254. aa editor traits substituteeSelectionEventHandler _Define: (|
  255.     _ parent*                 = aa editor traits selectionEventHandler.
  256.     ^ copy = (| c. |
  257.     c: resend.copy.
  258.     c substitutor: substitutor copy.
  259.     c
  260.     ).
  261.  
  262.     instructionText = ( 'Left: selects/expands Middle: substitutes Right: cancel' ).
  263.     handlerName = ('substituteeSelection'). 
  264.     isSubstitutionHandler = (true).
  265.  
  266.     copyUp: pt = (| np. |
  267.     equationSelection isValidSelection ifTrue: [
  268.         'substituting on: '  print. vue equation printLine.
  269.         'substituting for: ' print. equationSelection selectedPolynum printLine.
  270.         'substituting: ' print. substitutor printLine.
  271.         np: ((vue equation) substitute: substitutor For: equationSelection selectedPolynum).
  272.         'resulting in: ' print. np printLine.
  273.         vue equation: np.
  274.         resetHandler.
  275.         vue redraw.
  276.     ] False: [
  277.         vue topView userError: 'You must pick what to substitute into.'
  278.     ].
  279.     ).
  280. |)
  281.  
  282. aa editor prototypes substituteeSelectionEventHandler _Define: aa editor selectionEventHandler
  283. aa editor prototypes substituteeSelectionEventHandler _AddSlots: (|
  284.     _ parent*                 = aa editor traits substituteeSelectionEventHandler.
  285.     substitutor. " place to record what is going to be inserted "
  286. |)
  287.  
  288.